package com.blue.waffle.iwc.screens;

import java.sql.SQLException;
import java.util.List;

import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.ui.Window;
import com.badlogic.gdx.scenes.scene2d.utils.ActorGestureListener;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.blue.waffle.iwc.game.IWCGame;
import com.blue.waffle.iwc.screens.OptionsScreen.OptionsButtonListener.OptionsButton;
import com.blue.waffle.iwc.ui.ButtonActorListener;

public class AchievementsScreen extends AbstractScreen {

	private Window window;
	
	public AchievementsScreen(IWCGame game) {
		super(game);
		// TODO Auto-generated constructor stub
	}
	
	@Override
	public void show() {		
		super.show();
		Skin skin = getUiSkin();
		
		window = new Window("Achievements", skin);
		gameStage.addActor(window);
		window.setMovable(false);
		window.setBounds(WINDOW_PADDINGS, WINDOW_PADDINGS,
				IWCGame.VIRTUAL_WIDTH - WINDOW_PADDINGS * 2,
				IWCGame.VIRTUAL_HEIGHT - WINDOW_PADDINGS * 2);
		window.defaults().fill().padBottom(CELL_PADDINGS);
		
		window.row().space(10).padTop(20).minWidth(150);//.height(CELL_PADDINGS).fillX().right().bottom();
		
		
		window.add("Word");
		window.add("Easy\nScore/Time");
		window.add("Normal\nScore/Time");
		window.add("Hard\nScore/Time");
		window.row().space(5);
		Table table = new Table(skin);
		
		
		
		try {
			List<String[]> stats = game.getDatabaseHelper().getProfileLevelHelper().SelectStats();
			for (String[] s : stats)
			{
				
				table.row().minWidth(150);
				table.add(s[0]);
				table.add(s[1]+"/"+s[2]);
				table.add(s[3]+"/"+s[4]);
				table.add(s[5]+"/"+s[6]);
										

			}
			
		} catch (SQLException e) {			
			e.printStackTrace();
		}
		//table.size(window.getWidth(),window.getHeight());
		
		ScrollPane scrollPane = new ScrollPane(table);
		
		//scrollPane.size(window.getWidth(),window.getHeight());
	
		window.add(scrollPane).fill().colspan(4).padBottom(50);
		gameStage.addActor(getButtonTable(skin, new ButtonActorListener(this)
		{
			@Override
			public void clicked(InputEvent event, float x, float y) {			
				super.clicked(event, x, y);
				game.setScreen(new MenuScreen(game));
			}
		}).right().bottom());		
	}
}
